﻿namespace Web.Control.WWW.Share
{
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Collections.Generic;
    using System.Collections;

    using Lx.Web.Common.ControlsUI;
    using BLF.WWW_WWW.Contact;
    using Model.WWW_User.User;
    
    /// <summary>
    /// Default 的摘要说明
    /// </summary>
    public class Default : BaseControl
    {
        /// <summary>
        /// 提交的URL
        /// </summary>
        protected string UrlRefer = "";
        /// <summary>
        ///  当前会员昵称名
        /// </summary>
        protected string CNickName = "";
        /// <summary>
        /// 当前会员号
        /// </summary>
        private string Memberno = "";
        protected Repeater rfList;
        protected Literal litScript;
        private int pageIndex = 1;
        private int pageSize = 32;
        protected override void OnLoad(EventArgs e)
        {
            Memberno = HttpContext.Current.User.Identity.Name;
            if (Memberno == "")
            {
                Page.Response.Redirect("/user/clogin.htm?ReturnUrl=" + Page.Request.Url.AbsoluteUri);
                Page.Response.End();
                return;
            }            
            if (Request["Link"] != null)
            {
                UrlRefer = Request["Link"];
            }
            else
            {
                UrlRefer = HttpContext.Current.Request.UrlReferrer == null ? "" : HttpContext.Current.Request.UrlReferrer.AbsoluteUri;
            }
            if (UrlRefer == "")
            {
                Page.Response.End();                
            }            
            ArrayList outList;
            Model.CommonMessage common = Contacts.GetMemberFriends(Memberno, pageIndex, pageSize, out outList);
            List<MemberSimpleModel> friendsList = outList[1] as List<MemberSimpleModel>;            
            if (rfList != null)
            {
                rfList.DataSource = friendsList;
                rfList.DataBind();
            }            
            if (litScript != null)
            {
                litScript.Text = "<script>var Memberno='" + Memberno;                
                litScript.Text += "';var CNickName='" + Escape((string)outList[2]);
                litScript.Text += "';var AllFriendN=" + (new System.Web.Script.Serialization.JavaScriptSerializer()).Serialize(outList[3]);
                litScript.Text += ";var FriendList=" + (new System.Web.Script.Serialization.JavaScriptSerializer()).Serialize(friendsList);
                litScript.Text += ";var FriendPage=" + (new System.Web.Script.Serialization.JavaScriptSerializer()).Serialize(new BLF.PageableObject((int)outList[0], pageIndex, pageSize)) + ";</script>";
            }
            base.OnLoad(e);
        }
    }
}
